package com.note.common.domain;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;

/**
 * 用户实体类
 * 对应数据库中的user表
 */
@EqualsAndHashCode(callSuper = true)
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
@Entity(name = "user")
@TableName("user")
@Schema(description = "用户数据模型")
public class User extends BaseEntity {

    @Id
    @TableId(value = "id", type = IdType.AUTO)
    @Schema(description = "用户ID(自增主键)", example = "1")
    private Long id;

    @Column(nullable = false)
    @TableField
    @Schema(description = "用户名(唯一)", example = "zhangsan")
    private String username;

    @Column(nullable = false)
    @TableField
    @Schema(description = "加密密码", example = "$2a$10$CgA8skTnT8xFUUSrI8NWFeM5S8Wsjzz32G9v/qFvGYLBk75yFTqOC")
    private String password;

    @Column
    @TableField
    @Schema(description = "用户昵称", example = "张三")
    private String nickname;

    @Column(nullable = false)
    @TableField
    @Schema(description = "邮箱地址(唯一)", example = "user@example.com")
    private String email;

    @Column
    @TableField
    @Schema(description = "手机号", example = "1234567890")
    private String mobile;

    @Column
    @TableField
    @Schema(description = "头像URL", example = "https://example.com/avatar.jpg")
    private String avatar;

    @Column
    @TableField
    @Schema(description = "用户状态 0:禁用 1:正常", example = "1")
    private Integer status = 1;

    @Column
    @TableField
    @Schema(description = "删除标记 0:正常 1:删除", example = "0")
    private Integer deleted;


    @Column(name = "created_at")

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") // 修正月份MM和小时HH的大小写
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") // 修正时区写法
    @TableField(value = "created_at", fill = FieldFill.INSERT)
    @Schema(description = "创建时间", example = "2023-10-01T12:00:00")
    private LocalDateTime createdAt;


    @Column(name = "updated_at")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") // 修正月份MM和小时HH的大小写
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") // 修正时区写法
    @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE)
    @Schema(description = "更新时间", example = "2023-10-01T12:00:00")
    private LocalDateTime updatedAt;
}